﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using SAM_Edu.entity;

namespace SAM_Edu.dao
{
    public class daoLicense
    {
        static MySqlConnection conn;

        static bool status = false;
        public static bool StoreLicense(License l)
        {

            conn = DatabaseConnection.getConnection();
            string Query = "INSERT INTO license(name,address,logo) VALUES('" +  l.Name + "','" + l.Address + "', @img_data)";

            MySqlCommand cmd = new MySqlCommand(Query, conn);
            cmd.Parameters.AddWithValue("@img_data", l.Logo);

            conn.Open();
            int result = cmd.ExecuteNonQuery();

            if (result > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
            conn.Close();
            return status;
        }
        static bool status2;
        public static License GetLicensee()
        {
            License l;
            MySqlConnection conn = DatabaseConnection.getConnection();
            string Query = "Select * FROM license";
            MySqlCommand MyCommand2 = new MySqlCommand(Query, conn);
            MySqlDataReader MyReader2;
            conn.Open();
            MyReader2 = MyCommand2.ExecuteReader();
            while (MyReader2.Read())
            {
                
                l = new License(MyReader2[0].ToString(),MyReader2[1].ToString(),(byte[])MyReader2[2]);
                return l;
                break;
            }
            byte[] b = new byte[20];
            l = new License("Not Set", "Not set", b);
            return l;
            conn.Close();
            
        }
    }
}
